use super::trade_strategy::TradeStrategyIndicator;
use super::trade_strategy::TradeStrategyMaLine;
use crate::model::kline::Klt;
use crate::model::FudaThing;

use chrono::DateTime;
use chrono::Utc;
use serde::Deserialize;
use serde::Serialize;
use surrealdb::sql::Thing;
use ts_rs::TS;

///
/// 交易机器人，由([security](super::security),[trade_strategy](super::trade_strategy))决定唯一
///
#[derive(Debug, Serialize, Deserialize, Default, TS, Clone)]
#[ts(export)]
pub struct TradeBot {
    /// TradeBot Id, 自动创建
    #[ts(as = "Option<FudaThing>")]
    pub id: Option<Thing>,

    /// 证券ID，如SH.STOCK.600519, TradeBotWith Edge: in
    #[ts(as = "Option<FudaThing>")]
    pub security_id: Option<Thing>,

    /// 策略ID,本机器人由指定策略生成的, , TradeBotWith Edge: out
    #[ts(as = "Option<FudaThing>")]
    pub strategy_id: Option<Thing>,

    /// 机器状态
    pub is_running: Option<bool>,
    /// 最新一次回测时间
    pub last_backtested: Option<DateTime<Utc>>,
    /// 记录更新日期 HLC
    pub last_updated: Option<String>,

    //-----<field_values_from_trade_strategy_table>
    /// security symbol, get from security table by security_id
    pub security_symbol: Option<String>,
    /// security name, get from security table by security_id
    pub security_name: Option<String>,

    /// trade_strategy name, get from trade_strategy table by strategy_id
    pub strategy_name: Option<String>,
    /// 周期类型 Kline Type , get from trade_strategy table by strategy_id
    pub klt: Option<Klt>,
    /// 策略脚本通过验证, get from trade_strategy table by strategy_id
    pub script_verified: Option<bool>,
    /// 策略脚本, get from trade_strategy table by strategy_id
    pub script: Option<String>,
    /// K线窗口大小，get from trade_strategy table by strategy_id
    pub kl_window: Option<u8>,
    /// 主要用到的指标
    pub indicators: Option<Vec<TradeStrategyIndicator>>,
    /// 主要用到的均线
    pub malines: Option<Vec<TradeStrategyMaLine>>,
    //-----</field_values_from_trade_strategy_table>
}
